﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace EventScavenger
{
	static class Program
	{
		private static string serviceName = "Event Reaper";
		private static string displayName = "Event Reaper";
		private static string description = "Event Scavenger Reaper Service";

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		static void Main(string[] args)
		{
			string collectorName = "Default";		

			if (args.Length > 0)
			{                
				if (args[0].ToUpper() == "-INSTALL")
				{
                    string serviceParameters = "";
					if (args.Length > 1)
					{
						collectorName = args[1];
                        serviceName = "Event Reaper - " + collectorName;
						displayName = "Event Reaper - " + collectorName;
                        serviceParameters = "\"-Collector:" + collectorName + "\"";
					}
					if (args.Length > 2)
						displayName = args[2];
					if (args.Length > 3)
						description = args[3];

					HenIT.Services.ServiceRegister.InstallService(
						System.Reflection.Assembly.GetExecutingAssembly().Location,
						serviceName,
						displayName,
						description,
                        serviceParameters);
					return;
				}
				else if (args[0].ToUpper() == "-UNINSTALL")
				{
					



					return;
				}
				collectorName = HenIT.CommandLineUtils.GetCommand(args, "", "-Collector:");
			}
			if (collectorName.Length == 0)
				collectorName = Properties.Settings.Default.CollectorName;

			ServiceBase[] servicesToRun;
			servicesToRun = new ServiceBase[] 
			{ 
				new EventReaperService() { CollectorName = collectorName }
			};
			ServiceBase.Run(servicesToRun);
		}
	}
}
